home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / os / sprite.X11R3 / RCS / fileIO.c,v < prev    next >
Encoding:
Text File  |  1989-10-26  |  3.1 KB  |  166 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     88.09.08.18.15.35;  author ouster;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     87.06.11.17.47.06;  author deboor;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @functions for reading files in an OS-independent way
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @Intermediate check-in while converting to new C library.
  28. @
  29. text
  30. @/*-
  31.  * fileIO.c --
  32.  *    functions for os-independent file I/O
  33.  *
  34.  * Copyright (c) 1987 by the Regents of the University of California
  35.  *
  36.  * Permission to use, copy, modify, and distribute this
  37.  * software and its documentation for any purpose and without
  38.  * fee is hereby granted, provided that the above copyright
  39.  * notice appear in all copies.  The University of California
  40.  * makes no representations about the suitability of this
  41.  * software for any purpose.  It is provided "as is" without
  42.  * express or implied warranty.
  43.  *
  44.  * TODO:
  45.  *    - Snarf compressed-font stuff from 4.2bsd fileio.c
  46.  *
  47.  */
  48. #ifndef lint
  49. static char rcsid[] =
  50.     "$Header: fileIO.c,v 1.1 87/06/11 17:47:06 deboor Exp $ SPRITE (Berkeley)";
  51. #endif lint
  52.  
  53. #include    "spriteos.h"
  54. #include    <stdio.h>
  55.  
  56. /*-
  57.  *-----------------------------------------------------------------------
  58.  * FiOpenForRead --
  59.  *    Open a file for reading. The name needn't be null terminated.
  60.  *    We do it here if it ain't.
  61.  *
  62.  * Results:
  63.  *    An FID (FILE *)
  64.  *
  65.  * Side Effects:
  66.  *
  67.  *-----------------------------------------------------------------------
  68.  */
  69. FID
  70. FiOpenForRead (nameLen, name)
  71.     int              nameLen;      /* Length of the name */
  72.     char          *name;        /* The name itself */
  73. {
  74.     FILE *      stream;
  75.     char          *null_t_name = name;
  76.  
  77.     if (name[nameLen-1] != '\0') {
  78.     null_t_name = (char *)ALLOCATE_LOCAL (nameLen+1);
  79.     strncpy (null_t_name, name, nameLen);
  80.     null_t_name[nameLen] = '\0';
  81.     }
  82.  
  83.     stream = fopen (null_t_name, "r");
  84.  
  85.     if (null_t_name != name) {
  86.     DEALLOCATE_LOCAL(null_t_name);
  87.     }
  88.     return ((FID) stream);
  89. }
  90.  
  91. /*-
  92.  *-----------------------------------------------------------------------
  93.  * FiRead --
  94.  *    Read from an open stream
  95.  *
  96.  * Results:
  97.  *
  98.  * Side Effects:
  99.  *
  100.  *-----------------------------------------------------------------------
  101.  */
  102. int
  103. FiRead (buf, itemSize, numItems, fid)
  104.     char          *buf;
  105.     unsigned      itemSize;
  106.     unsigned      numItems;
  107.     FID              fid;
  108. {
  109.     return fread (buf, itemSize, numItems, (FILE *) fid);
  110. }
  111.  
  112. /*-
  113.  *-----------------------------------------------------------------------
  114.  * FiClose --
  115.  *    Close an open stream
  116.  *
  117.  * Results:
  118.  *
  119.  * Side Effects:
  120.  *
  121.  *-----------------------------------------------------------------------
  122.  */
  123. int
  124. FiClose (fid)
  125.     FID        fid;
  126. {
  127.     fclose ((FILE *)fid);
  128.     return (0);
  129. }
  130. @
  131.  
  132.  
  133. 1.1
  134. log
  135. @Initial revision
  136. @
  137. text
  138. @d15 2
  139. d21 1
  140. a21 1
  141.     "$Header$ SPRITE (Berkeley)";
  142. d25 1
  143. a25 3
  144. #define Time SpriteTime
  145. #include    <io.h>
  146. #undef Time
  147. d34 1
  148. a34 1
  149.  *    An FID (Io_Stream)
  150. d45 1
  151. a45 1
  152.     Io_Stream      stream;
  153. d50 1
  154. a50 1
  155.     String_NCopy (nameLen, name, null_t_name);
  156. d54 1
  157. a54 1
  158.     stream = Io_Open (null_t_name, "r");
  159. d80 1
  160. a80 1
  161.     return (Io_Read ((Io_Stream)fid, numItems, itemSize, buf));
  162. d98 1
  163. a98 1
  164.     Io_Close ((Io_Stream)fid);
  165. @
  166.